from .models import HawkeyeJob
from .services.scheduler import DjangoJobManager
from django.dispatch import receiver
from django.db.models.signals import post_save, post_delete

job_manager = DjangoJobManager()

@receiver(post_save, sender=HawkeyeJob)
def update_job(sender, instance, **kwargs):
    if instance.status=='0':
        job_manager.add_job(instance)
    else:
        job_manager.remove_job(instance.job_id)

@receiver(post_delete, sender=HawkeyeJob)
def delete_job(sender, instance, **kwargs):
    job_manager.remove_job(instance.job_id)